from typing import *
from math import inf


class Solution:
    def canSortArray(self, nums: List[int]) -> bool:
        lmx, c = -1, 0
        mn, mx, n = inf, -inf, len(nums)
        for i, num in enumerate(nums):
            if num.bit_count() == c:
                mn = min(mn, num)
                mx = max(mx, num)
            else:
                if mn < lmx:
                    return False
                c = num.bit_count()
                lmx = mx
                mn, mx = num, num
        if mn < lmx:
            return False
        return True


s = Solution()
print(s.canSortArray([20, 16]))
